﻿if (!$.format) {
    //格式化
    $.format = function (source, params) {
        if (arguments.length === 1) {
            return function () {
                var args = $.makeArray(arguments);
                args.unshift(source);
                return $.validator.format.apply(this, args);
            };
        }
        if (arguments.length > 2 && params.constructor !== Array) {
            params = $.makeArray(arguments).slice(1);
        }
        if (params.constructor !== Array) {
            params = [params];
        }
        $.each(params, function (i, n) {
            source = source.replace(new RegExp("\\{" + i + "\\}", "g"), function () {
                return n;
            });
        });
        return source;
    };
}
//日期格式化
Date.prototype.format = function (format) {
    var o = {
        "M+": this.getMonth() + 1,  //month
        "d+": this.getDate(),     //day
        "h+": this.getHours(),    //hour
        "m+": this.getMinutes(),  //minute
        "s+": this.getSeconds(), //second
        "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
        "S": this.getMilliseconds() //millisecond
    }

    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }

    for (var k in o) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
}


//共公临时变量
//解决IE8下checkbox onchange() 不好使的情况
$(function () {
    if ($.browser.msie) {
        $('input:checkbox').click(function () {
            this.blur();
            this.focus();
        });
    }
});
//var PublicConfig_public = {
//    validateErrorImg: "&nbsp;<img src='/Content/Images/check_warning.jpg'/>",
//    searchAlert: "<tr class='main_table_autotr'><td class='finddiv_altertd'>正在查找，请稍候...</td></tr>", //查询提示
//    noDataAlert: "<tr class='main_table_autotr'><td class='finddiv_altertd_nodata'>没有符合条件的查找结果</td></tr>",//没数据提示
//    errorMessage_top: 30,//错误信息提示离top距离
//    errorMessage_left: 7,//错误信息提示离top距离
//    moreBarCode_top: 25,//多条形码提示离top距离
//    moreBarCode_left: 0, //多条形码提示离top距离
//    queryStartTime: "2013-01-01"
//}


var UrlJump = {};
/**
* 随机数
*/
UrlJump.getSerialNumber = function () {
    var serial = Math.random() * 9999;
    return "serial=" + serial;
};

var numPublic = {
    sqlInt: 2147483647
}
var tempPublicVal_public = {
    maxzIndex: 9996,
    layerIndex: 1,
    wins: []
}

function GetTop() { return document.body.scrollTop || document.documentElement.scrollTop }
function GetWidth() { return self.innerWidth || document.documentElement.clientWidth; }
function GetHeight() { return self.innerHeight || document.documentElement.clientHeight }
function theight() {
    var d = document, b = d.body, e = d.documentElement;
    return Math.max(Math.max(b.scrollHeight, e.scrollHeight), Math.max(b.clientHeight, e.clientHeight))
}
function twidth() {
    var d = document, b = d.body, e = d.documentElement;
    return Math.max(Math.max(b.scrollWidth, e.scrollWidth), Math.max(b.clientWidth, e.clientWidth))
}

function getFullWidth() {
    var winWidth = 0;
    if (window.innerWidth) {
        winWidth = window.innerWidth;
    }
    else if ((document.body) && (document.body.clientWidth)) {
        winWidth = document.body.clientWidth;
    }
    //通过深入Document内部对body进行检测，获取窗口大小 
    if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) {
        winWidth = document.documentElement.clientWidth;
    }
    if (winWidth < 1024) {
        winWidth = 1024;
    }
    return winWidth;
}

function getFullHeight() {
    var screenHeight = document.body.scrollHeight;
    var winHeight;
    //获取窗口高度
    if (window.innerHeight) {
        winHeight = window.innerHeight;
    }
    else if ((document.body) && (document.body.clientHeight)) {
        winHeight = document.body.clientHeight;
    }

    //通过深入Document内部对body进行检测，获取窗口大小 
    if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) {
        winHeight = document.documentElement.clientHeight;
    }

    var divHeight = winHeight;
    if (screenHeight > winHeight) {
        divHeight = screenHeight;
    }
    //    if (divHeight < 768) {
    //        divHeight = 768;
    //    }
    return divHeight;
}

/**
**遮罩层显示

*/
function showDiv(idName) {
    var isExistLayer = false;
    for (var i = 0, len = tempPublicVal_public.wins.length; i < len; i++) {
        var winObj = tempPublicVal_public.wins[i];
        if (winObj.popWin == idName) {
            var layerId = winObj.layer;
            var $layerIdObj = $("#" + layerId);
            if ($layerIdObj.length > 0) {
                if ($layerIdObj.is(":hidden") == true) {
                    $layerIdObj.show();
                }
                isExistLayer = true;
                return;
            }
        }
    }

    var isIE = (document.all) ? true : false;
    // var isIE6 = isIE && ([/MSIE (\d)\.0/i.exec(navigator.userAgent)][0][1] == 6);
    var isIE6 = isIE && !window.XMLHttpRequest;

    var layerIndex = ++tempPublicVal_public.layerIndex
    var layerId = "layer" + layerIndex;
    var layerzIndex = ++tempPublicVal_public.maxzIndex;

    var layer = document.createElement("div");
    layer.id = layerId;
    layer.style.width = layer.style.height = "100%";
    layer.style.position = !isIE6 ? "fixed" : "absolute";
    layer.style.top = layer.style.left = 0;
    layer.style.backgroundColor = "#000";
    layer.style.zIndex = layerzIndex;
    layer.style.opacity = "0.6";
    document.body.appendChild(layer);

    var divzIndex = ++tempPublicVal_public.maxzIndex;
    var newbox = document.getElementById(idName);
    newbox.style.zIndex = divzIndex;
    newbox.style.display = "block"
    newbox.style.position = !isIE6 ? "fixed" : "absolute";
    newbox.style.top = newbox.style.left = "50%";
    newbox.style.marginTop = -newbox.offsetHeight / 2 + "px";
    newbox.style.marginLeft = -newbox.offsetWidth / 2 + "px";

    tempPublicVal_public.wins.push({ popWin: idName, layer: layerId, layerIndex: tempPublicVal_public.layerIndex });

    //    var sel = document.getElementsByTagName("select");
    //    for (var i = 0; i < sel.length; i++) {
    //        sel[i].style.visibility = "hidden";
    //    }
    function layer_iestyle() {
        layer.style.width = Math.max(document.documentElement.scrollWidth, document.documentElement.clientWidth)
+ "px";
        layer.style.height = Math.max(document.documentElement.scrollHeight, document.documentElement.clientHeight) +
"px";
    }
    // lｉｅｈｕｏ．ｎｅｔ
    function newbox_iestyle() {
        newbox.style.marginTop = document.documentElement.scrollTop - newbox.offsetHeight / 2 + "px";
        newbox.style.marginLeft = document.documentElement.scrollLeft - newbox.offsetWidth / 2 + "px";
    }
    if (isIE) { layer.style.filter = "alpha(opacity=60)"; }
    if (isIE6) {
        layer_iestyle()
        newbox_iestyle();
        window.attachEvent("onscroll", function () {
            newbox_iestyle();
        })
        window.attachEvent("onresize", layer_iestyle)
    }
    layer.onclick = function () {
        //            newbox.style.display = "none"; layer.style.display = "none"; for (var i = 0; i < sel.length; i++) {
        //                sel[i].style.visibility = "visible";
        //            } 
    }
}

function hiddenDiv(idName) {
    var layerId = '';
    for (var i = 0, len = tempPublicVal_public.wins.length; i < len; i++) {
        var winObj = tempPublicVal_public.wins[i];
        if (winObj.popWin == idName) {
            layerId = winObj.layer;
            tempPublicVal_public.wins.splice(i, 1);
            break;
        }
    }
    $("#" + layerId).remove();
    //$("#layer").hide();
    $("#layer").remove();
    $("#" + idName).hide();

    tempPublicVal_public.maxzIndex -= 2;
    tempPublicVal_public.layerIndex -= 1;

    if ($("#messageErrorTagPara").val() == "1") {
        $('#CameraEx').show();
        $("#messageErrorTagPara").val("0");
    }
}
//判断是否是整数
function isNumber(str) {
    if ("" == str) {
        return false;
    }
    var reg = /\D/;
    return str.match(reg) == null;
}

//判断是否是float类型
function checkFloat(val) {
    var result = true;
    var regex = /^[+|-]?\d+\.?\d*$/;
    if (!regex.test(val)) {
        result = false;
    }
    return result;
}

/**判断输入框中输入的日期格式为yyyy-mm-dd和正确的日期*/
function IsDate(mystring) {
    var reg = /^(\d{4})-(\d{2})-(\d{2})$/;
    var str = mystring;
    var arr = reg.exec(str);
    if (str == "") return true;
    if (!reg.test(str) && RegExp.$2 <= 12 && RegExp.$3 <= 31) {
        return false;
    }
    return true;

}

//通用日期转换方法


//返回 YYYY-MM-DD HH:mm:ss 字符串
function dateFromStringWithDateTime(str) {
    if (str == null || str == undefined) {
        return '';
    }

    var dateIs = true;
    if (str.indexOf("-") > 0) {
        dateIs = false;
    }

    var match;
    if (!(match = str.match(/\d+/))) {
        return false;
    }
    var date = new Date();

    if (dateIs) {
        date.setTime(match[0] - 0);
    } else {
        date.setTime(0 - match[0] - 0);
    }

    return DateToStrDateTime(date);
}

//日期转化为字符串格式： yyyy-mm-dd  HH:mm:ss
function DateToStrDateTime(dt) {
    var str = "";
    if (dt.getFullYear) {
        var y, m, d, h, mm, s;
        y = dt.getFullYear();
        m = dt.getMonth() + 1; //1-12
        m = "" + m;
        d = "" + dt.getDate();
        h = "" + dt.getHours();
        mm = "" + dt.getMinutes();
        s = "" + dt.getSeconds();

        if (m.length != 2) {
            m = "0" + m;
        }
        if (d.length != 2) {
            d = "0" + d;
        }
        if (h.length != 2) {
            h = "0" + h;
        }
        if (mm.length != 2) {
            mm = "0" + mm;
        }
        if (s.length != 2) {
            s = "0" + s;
        }

        str = "" + y + "-" + m + "-" + d + " " + h + ":" + mm + ":" + s;
    }
    return str;
}

//JSON 日期类型转换方法 
//返回 YYYY-MM-DD 字符串
function dateFromStringWithTime(str) {
    if (str == null || str == undefined) {
        return '';
    }

    var dateIs = true;
    if (str.indexOf("-") > 0) {
        dateIs = false;
    }

    var match;
    if (!(match = str.match(/\d+/))) {
        return false;
    }
    var date = new Date();

    if (dateIs) {
        date.setTime(match[0] - 0);
    } else {
        date.setTime(0 - match[0] - 0);
    }

    return DateToStr(date);
}

//日期转化为字符串格式： yyyy-mm-dd
function DateToStr(dt) {
    var str = "";
    if (dt.getFullYear) {
        var y, m, d;
        y = dt.getFullYear();
        m = dt.getMonth() + 1; //1-12
        m = "" + m;
        d = "" + dt.getDate();
        if (m.length != 2) {
            m = "0" + m;
        }
        if (d.length != 2) {
            d = "0" + d;
        }
        str = "" + y + "-" + m + "-" + d;
    }
    return str;
}

//JSON 日期类型转换方法 
//返回 MM-DD 字符串
function dateFromStringWithTimeMD(str) {
    if (str == null || str == undefined) {
        return '';
    }

    var dateIs = true;
    if (str.indexOf("-") > 0) {
        dateIs = false;
    }

    var match;
    if (!(match = str.match(/\d+/))) {
        return false;
    }
    var date = new Date();

    if (dateIs) {
        date.setTime(match[0] - 0);
    } else {
        date.setTime(0 - match[0] - 0);
    }

    return DateToStrMD(date);
}
//日期转化为字符串格式：mm-dd
function DateToStrMD(dt) {
    var str = "";
    if (dt.getFullYear) {
        var y, m, d;
        y = dt.getFullYear();
        m = dt.getMonth() + 1; //1-12
        m = "" + m;
        d = "" + dt.getDate();
        if (m.length != 2) {
            m = "0" + m;
        }
        if (d.length != 2) {
            d = "0" + d;
        }
        str = m + "-" + d;
    }
    return str;
}

//得到当前日期： yyyy-mm-dd
function GetDateNowYMD() {
    var dt = new Date();
    var str = "";
    if (dt.getFullYear) {
        var y, m, d;
        y = dt.getFullYear();
        m = dt.getMonth() + 1; //1-12
        m = "" + m;
        d = "" + dt.getDate();
        if (m.length != 2) {
            m = "0" + m;
        }
        if (d.length != 2) {
            d = "0" + d;
        }
        str = "" + y + "-" + m + "-" + d;
    }
    return str;
}

function GetServerDateNowYMD() {
    return $("#hidServerDate").val();
}

//得到当前日期： yyyy-mm-dd HH:mm:ss
function GetDateNowYMDHMS() {
    var dt = new Date();
    var str = "";
    if (dt.getFullYear) {
        var y, m, d;
        y = dt.getFullYear();
        m = dt.getMonth() + 1; //1-12
        m = "" + m;
        d = "" + dt.getDate();
        h = "" + dt.getHours();
        mm = "" + dt.getMinutes();
        s = "" + dt.getSeconds();

        if (m.length != 2) {
            m = "0" + m;
        }
        if (d.length != 2) {
            d = "0" + d;
        }
        if (h.length != 2) {
            h = "0" + h;
        }
        if (mm.length != 2) {
            mm = "0" + mm;
        }
        if (s.length != 2) {
            s = "0" + s;
        }
        str = "" + y + "-" + m + "-" + d + " " + h + ":" + mm + ":" + s;
    }
    return str;
}

//得到当前日期String： yyyymmddHHmmss
function GetDateNowYMDHMSStr() {
    var dt = new Date();
    var str = "";
    if (dt.getFullYear) {
        var y, m, d;
        y = dt.getFullYear();
        m = dt.getMonth() + 1; //1-12
        m = "" + m;
        d = "" + dt.getDate();
        h = "" + dt.getHours();
        mm = "" + dt.getMinutes();
        s = "" + dt.getSeconds();

        if (m.length != 2) {
            m = "0" + m;
        }
        if (d.length != 2) {
            d = "0" + d;
        }
        if (h.length != 2) {
            h = "0" + h;
        }
        if (mm.length != 2) {
            mm = "0" + mm;
        }
        if (s.length != 2) {
            s = "0" + s;
        }
        str = y + "" + m + "" + d + "" + h + "" + mm + "" + s;
    }
    return str;
}

//得到当前 年 如：2012-01-02 返回  2012
function GetDateNowYear() {
    var dt = new Date();

    return dt.getFullYear();
}


//得到当前 月 如：2012-03-02 返回  3
function GetDateNowMonth() {
    var dt = new Date();

    return dt.getMonth() + 1;
}


//得到当前 日 如：2012-03-02 返回  2
function GetDateNowDay() {
    var dt = new Date();
    var date = GetDateNowYMD();
    return parseInt(date.split("-")[2], 10);
}

//根据性别ID获取性别名称
function SexGetName(sexID) {
    var result = "女";
    if (sexID == 10) {
        result = "男";
    }
    return result;
}

//判断时间格式是否正确   正确返回  true
function checkTime(str) {
    var time = str.toString().match(/^(\d{1,2})(:)?(\d{1,2})\2(\d{1,2})$/);
    if (time == null) { return false; }
    if (parseInt(time[1], 10) >= 24 || parseInt(time[3], 10) >= 60 || parseInt(time[4], 10) >= 60) {
        return false
    }
    return true;
}

//替换要替换的字符串内所有满足条件的字符串
function replaceAll(oldStr, replaceOldStr, replaceNewStr) {
    var result = oldStr;
    while (true) {
        if (result.indexOf(replaceOldStr) > -1) {
            result = result.replace(replaceOldStr, replaceNewStr);
        } else {
            break;
        }
    }
    return result;
}



//将钱转换为两位小数   及   2.12345  变为 2.12    2.1453  变为2.14
function moneySubstring(moneyString) {
    var result = "";
    if (moneyString != null && moneyString != undefined) {
        var money = moneyString.toString();
        if (money != null && money.length > 0) {
            if (money.indexOf(".") > 0) {
                if (money.length - money.indexOf(".") > 2) {
                    result = money.substr(0, money.indexOf(".") + 3);
                } else {
                    result = money;
                    for (var i = 0; i < (3 - (money.length - money.indexOf("."))) ; i++) {
                        result += "0";
                    }
                }
            } else {
                result = money + ".00";
            }
        }
    }
    return result;
}


//将钱转换为1位小数   及   2.12345  变为 2.1    2.1453  变为2.1  直接抹掉分
function moneySubstring_1(moneyString) {
    var result = "";
    if (moneyString != null && moneyString != undefined) {
        var money = moneyString.toString();
        if (money != null && money.length > 0) {
            if (money.indexOf(".") > 0) {
                if (money.length - money.indexOf(".") > 1) {
                    result = money.substr(0, money.indexOf(".") + 2);
                } else {
                    result = money;
                    for (var i = 0; i < (2 - (money.length - money.indexOf("."))) ; i++) {
                        result += "0";
                    }
                }
            } else {
                result = money + ".0";
            }
        }
    }
    return result;
}

//将钱转换为0位小数   及   2.12345  变为 2    2.1453  变为2  直接抹掉角分
function moneySubstring_0(moneyString) {
    var result = "";
    if (moneyString != null && moneyString != undefined) {
        var money = moneyString.toString();
        if (money != null && money.length > 0) {
            if (money.indexOf(".") > 0) {
                result = money.substr(0, money.indexOf("."));
            } else {
                result = money;
            }
        }
    }
    return result;
}


//判断小数点后是否是两位小数
function moneyTypeIsRight(moneyString) {
    var result = true;

    if (moneyString != null && moneyString != undefined) {
        var money = moneyString.toString();
        if (money != null && money.length > 0) {
            if (money.indexOf(".") > 0) {
                if (money.length - money.indexOf(".") > 3) {
                    result = false;
                }
            }
        }
    }
    return result;
}


//删除table tr 根据table id   tr  id 
function delTrByID(trID) {
    $("tr[id=" + trID + "]").remove();
}

//*******身份证号码验证  start
//为值添加0  
function Append_zore(temp) {
    if (temp < 10) {
        return "0" + temp;
    }
    else {
        return temp;
    }
}
function checkPersonCode(personCode) {
    var result = 0;
    //身份证的地区代码对照  
    var aCity = { 11: "北京", 12: "天津", 13: "河北", 14: "山西", 15: "内蒙古", 21: "辽宁", 22: "吉林", 23: "黑龙江", 31: "上海", 32: "江苏", 33: "浙江", 34: "安徽", 35: "福建", 36: "江西", 37: "山东", 41: "河南", 42: "湖北", 43: "湖南", 44: "广东", 45: "广西", 46: "海南", 50: "重庆", 51: "四川", 52: "贵州", 53: "云南", 54: "西藏", 61: "陕西", 62: "甘肃", 63: "青海", 64: "宁夏", 65: "新疆", 71: "台湾", 81: "香港", 82: "澳门", 91: "国外" };
    //获取证件号码  
    var person_id = personCode;
    //合法性验证  
    var sum = 0;
    //出生日期  
    var birthday;
    //验证长度与格式规范性的正则  
    var pattern = new RegExp(/(^\d{15}$)|(^\d{17}(\d|x|X)$)/i);
    if (pattern.exec(person_id)) {
        //验证身份证的合法性的正则  
        pattern = new RegExp(/^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$/);
        if (pattern.exec(person_id)) {
            //获取15位证件号中的出生日期并转位正常日期       
            birthday = "19" + person_id.substring(6, 8) + "-" + person_id.substring(8, 10) + "-" + person_id.substring(10, 12);
        }
        else {
            person_id = person_id.replace(/x|X$/i, "a");
            //获取18位证件号中的出生日期  
            birthday = person_id.substring(6, 10) + "-" + person_id.substring(10, 12) + "-" + person_id.substring(12, 14);

            //校验18位身份证号码的合法性  
            for (var i = 17; i >= 0; i--) {
                sum += (Math.pow(2, i) % 11) * parseInt(person_id.charAt(17 - i), 11);
            }

            if (sum % 11 != 1) {
                //                $(this).addClass("txtRequired");
                //                alert("身份证号码不符合国定标准，请核对！");
                //                //$("#person_id").val("");  
                //                $("#birthday").val("")
                result = 1;
                return result;
            }
        }
        //检测证件地区的合法性                                  
        if (aCity[parseInt(person_id.substring(0, 2), 10)] == null) {
            //            $(this).addClass("txtRequired");
            //            alert("证件地区未知，请核对！");
            //            //$("#person_id").val("");  
            //            $("#birthday").val("");
            result = 1;
            return result;
        }
        var dateStr = new Date(birthday.replace(/-/g, "/"));

        //alert(birthday +":"+(dateStr.getFullYear()+"-"+ Append_zore(dateStr.getMonth()+1)+"-"+ Append_zore(dateStr.getDate())))  
        if (birthday != (dateStr.getFullYear() + "-" + Append_zore(dateStr.getMonth() + 1) + "-" + Append_zore(dateStr.getDate()))) {
            //            $(this).addClass("txtRequired");
            //            alert("证件出生日期非法！");
            //            //$("#person_id").val("");  
            //            $("#birthday").val("");
            //            return;
            result = 1;
            return result;
        }
    }
    else {
        //        $(this).addClass("txtRequired");
        //        alert("证件号码格式非法！");
        //        //$("#person_id").val("");  
        //        $("#birthday").val("")
        //        return;
        result = 1;
        return result;
    }
    return result;
}
//*******身份证号码验证  end

//*******邮箱验证  end
function checkEmail(mailValue) {
    var result = 0;
    // var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
    var reg = /^([a-zA-Z0-9]+[_|-|.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/;
    if (!reg.test(mailValue)) {
        //        msg = name + "请输入合法的Email地址";
        result = 1;
    }
    return result;
}

//比较两个日期  如果 startTime比endTime 大 则返回 true
function compareStartEndTime(startTime, endTime) {

    var startT = new Date(startTime.replace("-", "/"));
    var endT = new Date(endTime.replace("-", "/"));
    return startT > endT;
}

//根据会员卡类型ID得到会员卡类型
function GetConsumerTypeName(consumerTypeID) {
    return GetConsumerCategoryName(consumerTypeID);
}

//根据会员类型ID得到会员类型
function GetConsumerCategoryName(consumerTypeID) {
    if (consumerTypeID == "1" || consumerTypeID == 1) {
        return "银卡";
    } else if (consumerTypeID == "2" || consumerTypeID == 2) {
        return "金卡";
    } else if (consumerTypeID == "3" || consumerTypeID == 3) {
        return "白金卡";
    } else if (consumerTypeID == "0" || consumerTypeID == 0) {
        return "目标会员";
    } else {
        return "";
    }



    //    var jsonString = "{intItemCode:'" + consumerTypeID + "',intCategoryID:" + 1005 + "}";
    //    $.ajax({
    //        type: "Post",   //访问WebService使用Post方式请求
    //        contentType: "application/json", //WebService 会返回Json类型
    //        url: "../DataConfig/Index",  //调用WebService的地址和方法名称组合---WsURL/方法名
    //        data: jsonString,   //这里是要传递的参数，格式为 data: "{paraName:paraValue}",下面将会看到
    //        dataType: 'json',
    //        async: false,
    //        success: function (result) {     //回调函数，result，返回值
    //            if (result.success == false) {
    //                return result.Ent.ItemName;
    //            } else {
    //                return "";
    //            }
    //        },
    //        error: function (XMLHttpRequest, textStatus, errorThrown) {
    //            // 通常情况下textStatus和errorThown只有其中一个有值 
    //            //                $("#errorMessage").text("请检查网络是否安全，或联系管理员！");
    //        }
    //    });
}

//function GetConsumerAgesStage(agesStageID) {
//    var result = "";
//    switch (agesStageID) {
//        case 1:
//            result = "<19";
//            break;
//        case 2:
//            result = "20-25";
//            break;
//        case 3:
//            result = "26-30";
//            break;
//        case 4:
//            result = "31-35";
//            break;
//        case 5:
//            result = "36-40";
//            break;
//        case 6:
//            result = "41-45";
//            break;
//        case 7:
//            result = ">45";
//            break;

//    }
//    return result;
//}


function GetConsumerSkinsColor(skinsColorID) {
    return skinsColorID;
}

function GetConsumerSkins(colorID) {
    return colorID;

}

function GetProductGroup(productGroupID) {
    return productGroupID;

}


function GetProductBigClass(classID) {
    return classID;

}

function GetProductSmallClass(classID) {
    return classID;

}

function GetPosition(positionID) {
    return positionID;

}

//乘法 两个
function MultiplicationTwo(m1Str, m2Str) {
    var result;
    var arg1 = m1Str;
    var arg2 = m2Str;
    var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
    try { m += s1.split(".")[1].length } catch (e) { }
    try { m += s2.split(".")[1].length } catch (e) { }
    result = (Math.round(Number(s1.replace(".", ""))) * Math.round(Number(s2.replace(".", "")))) / Math.pow(10, m);

    return result;

    //    var result;
    //    var m1 = m1Str + "";
    //    var m2 = m2Str + "";
    //    if (m1 != undefined && m2 != undefined && checkFloat(m1) == true && checkFloat(m2) == true) {
    //        //小数位数  第一个数的小数位数
    //        var m1Median = 0;
    //        //小数位数  第二个数的小数位数
    //        var m2Median = 0;
    //        if (m1.indexOf(".") > 0) {
    //            m1Median = m1.length - m1.indexOf(".") - 1;
    //        }
    //        if (m2.indexOf(".") > 0) {
    //            m2Median = m2.length - m2.indexOf(".") - 1;
    //        }
    //        //扩大和缩小的倍数
    //        var multiple = 1;
    //        var multipleBig = 1;
    //        if (m1Median > m2Median) {
    //            for (var i = 0; i < m1Median; i++) {
    //                multipleBig = multipleBig * 10;
    //            }

    //            for (var i = 0; i < m1Median * 2; i++) {
    //                multiple = multiple * 10;
    //            }
    //        } else {
    //            for (var i = 0; i < m2Median; i++) {
    //                multipleBig = multipleBig * 10;
    //            }
    //            for (var i = 0; i < m2Median * 2; i++) {
    //                multiple = multiple * 10;
    //            }
    //        }

    //        var m1Big = m1 * multipleBig;
    //        var m2Big = m2 * multipleBig;

    //        var mResult = m1Big * m2Big;
    //        result = parseFloat(mResult) / multiple;
    //    }
    //    return result;
}


//乘法  三个
function MultiplicationThree(m1Str, m2Str, m3Str) {
    var result = MultiplicationTwo(m1Str, m2Str);
    result = MultiplicationTwo(result, m3Str);
    return result;

    //    var result;
    //    var m1 = m1Str + "";
    //    var m2 = m2Str + "";
    //    var m3 = m3Str + "";
    //    if (m1 != undefined && m2 != undefined && m3 != undefined && checkFloat(m1) == true && checkFloat(m2) == true && checkFloat(m3) == true) {
    //        //小数位数  第一个数的小数位数
    //        var m1Median = 0;
    //        //小数位数  第二个数的小数位数
    //        var m2Median = 0;
    //        //小数位数  第三个数的小数位数
    //        var m3Median = 0;
    //        if (m1.indexOf(".") > 0) {
    //            m1Median = m1.length - m1.indexOf(".") - 1;
    //        }
    //        if (m2.indexOf(".") > 0) {
    //            m2Median = m2.length - m2.indexOf(".") - 1;
    //        }
    //        if (m3.indexOf(".") > 0) {
    //            m3Median = m3.length - m3.indexOf(".") - 1;
    //        }
    //        //扩大和缩小的倍数
    //        var multiple = 1;
    //        var multipleBig = 1;
    //        if (m1Median > m2Median && m1Median > m3Median) {
    //            for (var i = 0; i < m1Median; i++) {
    //                multipleBig = multipleBig * 10;
    //            }
    //            for (var i = 0; i < m1Median * 3; i++) {
    //                multiple = multiple * 10;
    //            }
    //        } else if (m2Median > m1Median && m2Median > m3Median) {
    //            for (var i = 0; i < m2Median; i++) {
    //                multipleBig = multipleBig * 10;
    //            }
    //            for (var i = 0; i < m2Median * 3; i++) {
    //                multiple = multiple * 10;
    //            }
    //        } else {
    //            for (var i = 0; i < m3Median; i++) {
    //                multipleBig = multipleBig * 10;
    //            }
    //            for (var i = 0; i < m3Median * 3; i++) {
    //                multiple = multiple * 10;
    //            }
    //        }

    //        var m1Big = m1 * multipleBig;
    //        var m2Big = m2 * multipleBig;
    //        var m3Big = m3 * multipleBig;

    //        var mResult = m1Big * m2Big * m3Big;
    //        result = parseFloat(mResult) / multiple;
    //    }
    //    return result;
}

//除法
function divisionTwo(m1Str, m2Str) {
    var result;
    var arg1 = m1Str;
    var arg2 = m2Str;
    var t1 = 0, t2 = 0, r1, r2;
    try { t1 = arg1.toString().split(".")[1].length } catch (e) { }
    try { t2 = arg2.toString().split(".")[1].length } catch (e) { }
    with (Math) {
        r1 = Number(arg1.toString().replace(".", ""))
        r2 = Number(arg2.toString().replace(".", ""))
        result = ((r1 / r2) * pow(10, t2 - t1));
    }
    return result;
}

//加法 两个
function AdditionTwo(m1Str, m2Str) {
    var result;
    var arg1 = m1Str;
    var arg2 = m2Str;
    var r1, r2, m;
    try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
    try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
    m = Math.pow(10, Math.max(r1, r2))
    result = (Math.round(Number(arg1) * m) + Math.round(Number(arg2) * m)) / m;

    return result;

    //    var m1 = m1Str + "";
    //    var m2 = m2Str + "";
    //    if (m1 != undefined && m2 != undefined && checkFloat(m1) == true && checkFloat(m2) == true) {
    //        //小数位数  第一个数的小数位数
    //        var m1Median = 0;
    //        //小数位数  第二个数的小数位数
    //        var m2Median = 0;
    //        if (m1.indexOf(".") > 0) {
    //            m1Median = m1.length - m1.indexOf(".") - 1;
    //        }
    //        if (m2.indexOf(".") > 0) {
    //            m2Median = m2.length - m2.indexOf(".") - 1;
    //        }
    //        //扩大和缩小的倍数
    //        var multipleBig = 1;
    //        if (m1Median > m2Median) {
    //            for (var i = 0; i < m1Median; i++) {
    //                multipleBig = multipleBig * 10;
    //            }

    //        } else {
    //            for (var i = 0; i < m2Median; i++) {
    //                multipleBig = multipleBig * 10;
    //            }
    //        }

    //        var m1Big = m1 * multipleBig;
    //        var m2Big = m2 * multipleBig;

    //        var mResult = m1Big + m2Big;
    //        result = parseFloat(mResult) / multipleBig;
    //    }
    //    return result;
}



//减法 两个    第一个数为被减的数  第二个是减数
function SubtractionTwo(m1Str, m2Str) {
    var result;
    var arg1 = m1Str;
    var arg2 = m2Str;
    var r1, r2, m, n;
    try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
    try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
    m = Math.pow(10, Math.max(r1, r2));
    n = (r1 >= r2) ? r1 : r2;
    result = ((Math.round(arg1 * m) - Math.round(arg2 * m)) / m).toFixed(n);
    return result;


    //    var m1 = m1Str + "";
    //    var m2 = m2Str + "";
    //    if (m1 != undefined && m2 != undefined && checkFloat(m1) == true && checkFloat(m2) == true) {
    //        //小数位数  第一个数的小数位数
    //        var m1Median = 0;
    //        //小数位数  第二个数的小数位数
    //        var m2Median = 0;
    //        if (m1.indexOf(".") > 0) {
    //            m1Median = m1.length - m1.indexOf(".") - 1;
    //        }
    //        if (m2.indexOf(".") > 0) {
    //            m2Median = m2.length - m2.indexOf(".") - 1;
    //        }
    //        //扩大和缩小的倍数
    //        var multipleBig = 1;
    //        if (m1Median > m2Median) {
    //            for (var i = 0; i < m1Median; i++) {
    //                multipleBig = multipleBig * 10;
    //            }

    //        } else {
    //            for (var i = 0; i < m2Median; i++) {
    //                multipleBig = multipleBig * 10;
    //            }
    //        }

    //        var m1Big = m1 * multipleBig;
    //        var m2Big = m2 * multipleBig;

    //        var mResult = m1Big - m2Big;
    //        result = parseFloat(mResult) / multipleBig;
    //    }
    //    return result;
}

function Rounding2(d) {
    var result = d;
    if (d.toString().length > 4) {
        var she = d.toString().substr(4, 1); //得到判断是否应该四舍五入的那位
        var mowei = d.toString().substr(3, 1); //得到结果最后一位
        var mo2 = d.toString().substr(2, 1); //得到结果倒数第二位
        var gewei = d.toString().substr(0, d.toString().indexOf("."));
        if (parseInt(she, 10) > 4) {
            if (parseInt(mowei, 10) < 9) {
                mowei = parseInt(mowei, 10) + 1;
            } else {
                mo2 = parseInt(mo2, 10) + 1;
                if (mo2 > 9) {
                    mo2 = "0";
                    gewei = 1;
                }

                mowei = 0;
            }
        }
        result = gewei + "." + mo2 + mowei;
    }

    return result;
}

//限制输入字符
function limitInput(obj) {
    obj.value = obj.value.replace(/[!|@|#|\$|%|\^|&|\*|(|)|?|-]/g, '')
}

//是否匹配
function IsTest(reg, value) {
    if (value != "") {
        if (reg.test(value)) {
            return true;
        }
        else {
            return false;
        }
    }
    return false;
}

var printObj;  //打印对象  全局变量

//文本框将光标定位到最后
function setSelection(editor, pos) {
    if (editor.setSelectionRange) {

        editor.focus();
        editor.setSelectionRange(pos, pos);
    } else if (editor.createTextRange) {
        var textRange = editor.createTextRange();
        textRange.collapse(true);
        textRange.moveEnd("character", pos);
        textRange.moveStart("character", pos);
        textRange.select();
    }
}
////var myw = screen.availWidth+10;   //定义一个myw，接受到当前全屏的宽   

////var myh = screen.availHeight+10;  //定义一个myw，接受到当前全屏的高   

////window.moveTo(0, 0);           //把window放在左上脚   

////window.resizeTo(myw, myh);     //把当前窗体的长宽跳转为myw和myh  
//var screenWidth = window.screen.width - 10; 
//var screenHeight = window.screen.height;
//this.window.screenHeight = screenHeight;
//this.window.screenWidth = screenWidth;
////a
////window.open('', '', 'width=' + screenWidth + ',height=' + screenHeight + ',left=0,top=0,titlebar=no,menubar=no,toolbar=no,location=no,status=no,scrollbars=yes,resizable=no');

//根据宽度数组设置新行的列宽
function SetTDWidth(trHtml, arrWidth) {
    for (var i = 0, len = arrWidth.length; i < len; i++) {
        if (arrWidth[i] == 0) { arrWidth[i] = "auto"; }
        else {
            arrWidth[i] = arrWidth[i] + "px";
        }
    }
    return $.format(trHtml, arrWidth);
}
//取掉空
function RemoveNull(value) {
    if (value && value != "null") {
        return value;
    }
    else {
        return "";
    }
}

//得到当前字符串的字节长度
function getByteCount(checkStr) {
    var byteLength = 0;
    if (checkStr != undefined && checkStr != null) {
        for (var i = 0; i < checkStr.length; i++) {
            if (checkStr.charCodeAt(i) > 255) {
                byteLength += 2;
            } else {
                byteLength++;
            }
        }
    }
    return byteLength;
}


//检测是否有特殊字符
function CheckSpecialCharacters(str) {
    var myReg = /^[^@\/\'\\\"#$%&\^\*]+$/;
    if (myReg.test(str)) {
        return true;
    }
    return false;
}

//弹出窗口改变方法
function changeWindows(nowWindow, openWindow) {
    hiddenDiv(nowWindow);
    showDiv(openWindow);
}
/************打印公用方法   start*************/
//printID  要打印的ID  比如:#prindtID
function printA4(printID) {
    $(printID).jqprint({ debug: false, importCSS: true, printContainer: true, operaSupport: true });
}
/************打印公用方法   end*************/

// Json格式对于字符串特殊字符的处理
function String2Json(s) {
    var newstr = "";
    for (var i = 0; i < s.length; i++) {
        var c = s.charAt(i);

        switch (c) {
            case '\"':
                newstr += "\\\"";
                break;
            case '\\':
                newstr += "\\\\";
                break;
            case '/':
                newstr += "\\/";
                break;
            case '\b':
                newstr += "\\b";
                break;
            case '\f':
                newstr += "\\f";
                break;
            case '\n':
                newstr += "\\n";
                break;
            case '\r':
                newstr += "\\r";
                break;
            case '\t':
                newstr += "\\t";
                break;
            case '\'':
                newstr += "\\\'";
                break;
            default:
                newstr += c;
        }
    }
    return newstr;
}

function PageAlert(str, s) {
    if (s == "")
        s = 1000;

    ShowAlert(str);
   setTimeout("hideAlert();",s);
}

function ShowAlert(str) {
    var ileft = parseInt($(document).width()) / 2 - 150;
    var itop = parseInt($(window).scrollTop()) + 200;
    $("#alertmessage").css("left", ileft + "px");
    $("#alertmessage").css("top", itop + "px");
    $("#alertmessage").html(str);
    $("#alertmessage").fadeIn();
}
function hideAlert() {
    $("#alertmessage").fadeOut();
    $("#alertmessage").html("");
}



// 添加翻页控件 id：需要添加控件的DIV id属性
//             Condition:翻页控件中需要注入的其他查询条件eg: &team=3323
//             url:地址
function AddPageContent(id, pageNow, pageCount, url, Condition) {
    if (pageNow <= 0)
        pageNow = 1;

    if (pageNow > pageCount)
        pageNow = pageCount;

    var arrHtml = [];

    arrHtml.push("<div class=\"pagination\">");
    arrHtml.push("<span class=\"page_nav_area\">");
    var prevPage = pageNow - 1;
    var nextPage = pageNow + 1;
    if (pageNow != 1 && pageCount > 1) {
        //arrHtml.push(" <a href=\"?page=1" + Condition + "\" class=\"btn page_first\">第一页</a>");
        arrHtml.push(" <a href=\"" + url + "?page=" + prevPage + Condition + "\" class=\"btn page_prev\"> <i class=\"arrow\"></i></a>");
    }
    if (pageCount > 0)
        arrHtml.push(" <span class=\"page_num\"><label>" + pageNow + "</label><span class=\"num_gap\">/</span><label>" + pageCount + "</label></span>");

    if (pageNow < pageCount && pageCount != 1) {
        arrHtml.push(" <a href=\"" + url + "?page=" + nextPage + Condition + "\" class=\"btn page_next\"> <i class=\"arrow\"></i></a>");
        //arrHtml.push(" <a href=\"?page=" + pageCount + Condition + "\" class=\"btn page_last\">最后一页</a>");
    }

    if (pageCount > 1) {
        arrHtml.push(" <span class=\"goto_area\"> <input type=\"text\"> <a href=\"#\" onclick=\"MZGotoPage(this,'" + url + "','" + Condition + "')\" class=\"btn page_go\">跳转</a> <input type=\"hidden\" value='" + pageCount + "'></span>");
    }

    arrHtml.push("</span>");
    arrHtml.push("</div>");


    $("#" + id).html(arrHtml.join(""));
}
// 跳转
function MZGotoPage(obj, url, query) {
    var val = $.trim($(obj).prev().val());
    if (val == "") {
        alert("请输入页码!");
        return false;
    }
    if (!isNumber(val)) {
        alert("请输入有效页码!");
        return false;
    }

    if (parseInt(val) > parseInt($(obj).next().val())) {
        alert("请输入有效页码!");
        return false;
    }

    location.href = url + "?page=" + val + query;
}


function ViewPop(url, title, width, height, handler) {
    ymPrompt.win({ message: url, handler: handler, width: width, height: height, title: '' + title + '', iframe: true });
}


var frm = null;
var timer = null
function DownLoad(url) {
    frm = document.createElement("IFRAME");
    frm.style.display = "none";
    document.body.appendChild(frm);
    frm.contentWindow.location.href = url

    timer = setInterval(checkload, 200);

}
function checkload() {
    if (frm.contentWindow.document.readyState == "complete") {
        frm.contentWindow.document.execCommand("SaveAs");
        clearInterval(timer)
    }
    document.body.removeChild(frm);
}

function removeHTMLTag(str) {
    str = str.replace(/<\/?[^>]*>/g, ''); //去除HTML tag
    str = str.replace(/[ | ]*\n/g, '\n'); //去除行尾空白
    //str = str.replace(/\n[\s| | ]*\r/g,'\n'); //去除多余空行
    str = str.replace(/ /ig, '');//去掉
    return str;
}

String.prototype.replaceAll = function (s1, s2) {
    return this.replace(new RegExp(s1, "gm"), s2);
}
//---------------超级账号 start----------------------
// 0:代表隐藏分组和区域
function SelCustomer(type) {
    var strValue = "";
    var brandid = "";
    var brandname = "";
    var teamtype = ""; //-2:代表全部会员，
    var teamid = "";// 1:代表分组
    var province = "";
    var city = "";

    if ($("#hascheckbrand").find("div.singleCustom").length > 0) {
        for (var i = 0; i < $("#hascheckbrand").find("div.singleCustom").length; i++) {
            brandid = $("#hascheckbrand").find("div.singleCustom").eq(i).attr("data-value");
            brandname = $("#hascheckbrand").find("div.singleCustom").eq(i).attr("data-name");
            teamtype = $("#hascheckbrand").find("div.singleCustom").eq(i).attr("data-teamtype");
            teamid = $("#hascheckbrand").find("div.singleCustom").eq(i).attr("data-teamid");
            province = $("#hascheckbrand").find("div.singleCustom").eq(i).attr("data-province");
            city = $("#hascheckbrand").find("div.singleCustom").eq(i).attr("data-city");

            strValue += "|" + brandid + "," + brandname + "," + teamtype + "," + teamid + "," + province + "," + city;
        }
        if (strValue != "")
            strValue = strValue.substring(1);
    }

    ViewPop('/MaterialManage/SelCustomer?type=' + type + '&brandid=' + encodeURI(strValue), '选择商家', 900, 590, AdminCheckBrand);
}
//超级账号选择商家
function AdminCheckBrand(data) {
    if (data.indexOf('close') > -1)
        return false;
    //alert(data);
    //return false;

    var str = "";
    var dataObj = eval("(" + data + ")"); //转换为json对象
    var brandid = "";
    var brandname = "";
    var teamtype = ""; //-2:代表全部会员，
    var teamid = "";// 1:代表分组
    var province = "";
    var city = "";

    var IsExists = false;
    //str = $("#hascheckbrand").html();
    var arrBrandID = "";
    for (var i = 0; i < $("#hascheckbrand").find("div.singleCustom").length; i++) {
        arrBrandID += "," + $("#hascheckbrand").find("div.singleCustom").eq(i).attr("data-value");
    }
    if (arrBrandID != "") {
        arrBrandID = arrBrandID + ",";
    }
    var arrExistBrandID = "";
    $.each(dataObj, function (idx, item) {
        brandid = item.brandid;
        brandname = unescape(item.brandname);
        teamtype = item.teamtype;
        teamid = item.teamid;
        province = unescape(item.province);
        city = unescape(item.city);
        for (var i = 0; i < $("#hascheckbrand").find("div.singleCustom").length; i++) {
            if ($("#hascheckbrand").find("div.singleCustom").eq(i).attr("data-value") == "-1" || brandid == $("#hascheckbrand").find("div.singleCustom").eq(i).attr("data-value")) {
                $("#hascheckbrand").find("div.singleCustom").eq(i).remove();
            }
        }
        // if (!IsExists) {
        str += " <div class=\"singleCustom\" data-value=\"" + brandid + "\" data-name=\"" + brandname + "\" data-teamtype=\"" + teamtype + "\" ";
        str += " data-teamid=\"" + teamid + "\" data-province=\"" + province + "\" data-city=\"" + city + "\">";
        str += "" + brandname + "<i onclick=\"DelHasCheckBrand(this);\"></i></div>";
        // }
    });
    $("#hascheckbrand").html(str);

}

function DelHasCheckBrand(obj) {
    $(obj).parent().remove();
}


//获取已选择的品牌商
function GetCheckBrand() {
    var str = "";
    var brandname = "";
    var brandid = "";
    var TeamType = "";
    var TeamID = "";
    var Province = "";
    var City = "";
    for (var i = 0; i < $("#SelCustomerTable").find("input[name*=indexcheck]:checked").length; i++) {
        //if ($("#SelCustomerTable").find("input[name*=indexcheck]").eq(i).attr("checked") == "checked" || $("input[name*=indexcheck]").eq(i).attr("checked") == true) {
        brandname = $("#SelCustomerTable").find("input[name*=indexcheck]:checked").eq(i).attr("data-value");
        if (brandname == "")
            brandname = $("#SelCustomerTable").find("input[name*=indexcheck]:checked").eq(i).attr("data-name");
        brandid = $("#SelCustomerTable").find("input[name*=indexcheck]:checked").eq(i).attr("value");

         TeamType = $("#SelCustomerTable").find("input[name*=indexcheck]").eq(i).parent().parent().parent().find("div.setbossteamtype").find("a.jsDropdownBt").attr("data-value");
         TeamID = $("#SelCustomerTable").find("input[name*=indexcheck]").eq(i).parent().parent().parent().find("div.setbossteams").find("a.jsDropdownBt").attr("data-value");
         Province = $("#SelCustomerTable").find("input[name*=indexcheck]").eq(i).parent().parent().parent().find("div.ddlProvince").find("jsBtLabel.jsBtLabel").text();
         City = $("#SelCustomerTable").find("input[name*=indexcheck]").eq(i).parent().parent().parent().find("div.ddlCity").find("jsBtLabel.jsBtLabel").text();

        str += " <div class=\"singleCustom\" data-value=\"" + brandid + "\" data-name=\"" + brandname + "\">";
        str += "" + brandname + "<i onclick=\"delBrandCheckBox(this,'" + brandid + "');\"></i></div>";
    }

    $("#checkbrand").html(str);
}

//勾选单个品牌商 type:checkbox代表勾选
function GetCheckSingleBrand(obj,type) {
    var str = "";
    var type = "";
    if ($(obj).parent().parent().parent().find("i.icon_checkboxNotxt").attr("data-value") == "selected") {
        type = "add";
    } else {
        //判断事件是选择分组或是城市
        if (type != "checkbox") {
            return false;
        }
    }
    var brandid = $(obj).parent().parent().parent().find("input[name*=indexcheck]").attr("value");
    var brandname = $(obj).parent().parent().parent().find("input[name*=indexcheck]").attr("data-value");

    var TeamType = $(obj).parent().parent().parent().find("select.ddlTeamtype").val();
    var TeamID = $(obj).parent().parent().parent().find("select.ddlTeams").val();
    var Province = $(obj).parent().parent().parent().find("select.ddlProvince").val();
    var City = $(obj).parent().parent().parent().find("select.ddlCity").val();

    if (typeof (TeamType) == 'undefined') {
        TeamType = "-2";
    }
    if (typeof (TeamID) == 'undefined' || TeamID=="") {
        TeamID = "";
        TeamType = "-2";
    }
    if (typeof (Province) == 'undefined') {
        Province = "";
    }
    if (typeof (City) == 'undefined') {
        City = "";
    }
    var strValue = "";
    //brandid,brandname,teamtype,teamid,provice,city|brandid,brandname,teamtype,teamid,provice,city
    var strCheckBrandName = $("#checkedbrandname").val();
    
    if (strCheckBrandName != "") {
        var arrCheckBrandName = strCheckBrandName.split('|');
        for (var i = 0; i < arrCheckBrandName.length;i++){
            if (arrCheckBrandName[i].split(',')[0] == brandid) {
                continue;
            }
            var strBrandName = arrCheckBrandName[i].split(',')[1];
            str += " <div class=\"singleCustom\" data-value=\"" + arrCheckBrandName[i].split(',')[0] + "\" data-name=\"" + unescape(strBrandName) + "\">";
            str += "" + unescape(strBrandName) + "<i onclick=\"delBrandCheckBox(this,'" + arrCheckBrandName[i].split(',')[0] + "');\"></i></div>";

            strValue += "|" + arrCheckBrandName[i].split(',')[0] + "," + strBrandName + "," + arrCheckBrandName[i].split(',')[2] + "," + arrCheckBrandName[i].split(',')[3] + "," + arrCheckBrandName[i].split(',')[4] + "," + arrCheckBrandName[i].split(',')[5];
        }
        if (strValue != "")
            strValue = strValue.substring(1);
    }
    if (type = "add") {
        if (strValue!="")
            strValue += "|" + brandid + "," + escape(brandname) + "," + TeamType + "," + TeamID + "," + Province + "," + City;
        else
            strValue = brandid + "," + escape(brandname) + "," + TeamType + "," + TeamID + "," + Province + "," + City;
        str += " <div class=\"singleCustom\" data-value=\"" + brandid + "\" data-name=\"" + brandname + "\">";
        str += "" + brandname + "<i onclick=\"delBrandCheckBox(this,'" + brandid + "');\"></i></div>";
    }
    $("#checkedbrandname").val(strValue)
    $("#checkbrand").html(str);
}

//删除已选商家
function delBrandCheckBox(obj, brandid) {
    $(obj).parent().remove();
    for (var i = 0; i < $("#BossuserGroups").find("input[name*=indexcheck]:checked").length; i++) {
        if ($("#BossuserGroups").find("input[name*=indexcheck]:checked").eq(i).attr("value") == brandid) {
            $("#BossuserGroups").find("input[name*=indexcheck]:checked").eq(i).parent().find("i.icon_checkboxNotxt").removeClass("selected");
            $("#BossuserGroups").find("input[name*=indexcheck]:checked").eq(i).removeAttr("checked");
            $("#BossuserGroups").find("input[name*=indexcheck]:checked").eq(i).parent().find("i.icon_checkboxNotxt").attr("data-value", "");
            break;
        }
    }
}

//搜索超级账号下子商家
function SearchBossBrand() {
    var strval = $.trim($("#groupSearch").val());
    // if (strval == "" || strval == "输入关键字") {
    //PageAlert("请输入关键字", 3000);
    //    alert("请输入关键字");
    //    return false;
    // }
    var jsonString = "{\"name\":\"" + escape(strval) + "\"}";
    $.ajax({
        type: "Post",   //访问WebService使用Post方式请求
        contentType: "application/json", //WebService 会返回Json类型
        url: "../MaterialManage/SearchChildBoss?t=" + UrlJump.getSerialNumber(),  //调用WebService的地址和方法名称组合---WsURL/方法名
        data: jsonString,   //这里是要传递的参数，格式为 data: "{paraName:paraValue}",下面将会看到
        dataType: 'json',
        success: function (result) {     //回调函数，result，返回值
            if (result.messagecode == 5) {
                var str = "";
                var strBrandName = "";
                var strCompanyName = "";
                var strAddresses = "";
                for (var i = 0; i < result.data.length; i++) {
                    // if (result.data[i].BrandName!=null)
                    strBrandName = result.data[i].BrandName;
                    // if (result.data[i].BrandName != null)
                    strCompanyName = result.data[i].CompanyName;
                    // if (result.data[i].Addresses != null)
                    strAddresses = result.data[i].Addresses;

                    str += "<tr>";
                    str += "<th class=\"table_cell userid\" style=\"width: 10%\">";
                    str += "  <label for=\"selectAll\" class=\"frm_checkbox_labelNomargin\">";
                    str += "   <i class=\"icon_checkboxNotxt\" data-value=\"\" onclick=\"SingleCheckBox(this);\"></i>";
                    str += "    <input type=\"checkbox\" class=\"frm_checkbox\" name=\"indexcheck\" value=\"" + result.data[i].VipUserID + "\" data-value=\"" + strBrandName + "\" data-name=\"" + strCompanyName + "\" />";
                    str += "  </label>";
                    str += "</th>";
                    str += " <th class=\"table_cell userid\" style=\"width: 20%\">" + strBrandName + "</th>";
                    str += " <th class=\"table_cell nickname\" style=\"width: 30%;text-align:left;padding-left:10px;\">" + strCompanyName + "</th>";
                    str += "<th class=\"table_cell store\" style=\"width: 40%;text-align:left;padding-left:10px;\">" + strAddresses + "</th>";
                    str += "</tr>";
                }

                $("#selectAllcheckbox").parent().find("i.icon_checkbox").removeClass("selected");
                $("#selectAllcheckbox").parent().find("i.icon_checkbox").attr("data-value", "");
                $("#BossuserGroups").html(str);
            } else {
                alert(result.message);
            }
            GetCheckBrand();
            return false;
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(errorThrown);
        }
    });
}


function AllChildBoss() {
    var str = ""
    str = "<div class=\"singleCustom\" data-value=\"-1\" data-name=\"全部商家\" data-teamtype=\"-2\" ";
    str += " data-teamid=\"\" data-province=\"\" data-city=\"\">全部商家<i onclick=\"DelHasCheckBrand(this);\"></i></div>";
    $("#hascheckbrand").html(str);
}

function GetTeamsByBossIDPublic(obj, boss) {
    GetCheckSingleBrand(obj, 'team');

    var teamtype = $(obj).val();
    $(obj).parent().find("select.ddlTeams").show();
    if (teamtype == "-2") {
        //$(obj).parent().find("select.ddlTeams").html("");
        $(obj).parent().find("select.ddlTeams").hide();
        return false;
    }
    var jsonString = "{\"BossID\":\"" + escape(boss) + "\"}";
    $.ajax({
        type: "Post",   //访问WebService使用Post方式请求
        contentType: "application/json", //WebService 会返回Json类型
        url: "../MemberManage/GetTeamsByBossID?t=" + UrlJump.getSerialNumber(),  //调用WebService的地址和方法名称组合---WsURL/方法名
        data: jsonString,   //这里是要传递的参数，格式为 data: "{paraName:paraValue}",下面将会看到
        dataType: 'json',
        success: function (result) {     //回调函数，result，返回值
            if (result.messagecode == 5) {
                var str = "";
                //if (result.NoTeam>0)
                //    str += "<option value=\"0\">未分组 ("+result.NoTeam+")</option>";
                //if (result.NoLoginTeam > 0)
                //    str += "<option value=\"0\">未登录用户 (" + result.NoLoginTeam + ")</option>";
                //if (result.BlackTeam > 0)
                //    str += "<option value=\"0\">黑名单 (" + result.BlackTeam + ")</option>";

                if (result.data.length > 0) {
                    str += "<option value=\"\">选择分组</option>";
                    for (var i = 0; i < result.data.length; i++) {
                        if (parseInt(result.data[i].ObjCount) > 0) {
                           // alert(result.data[i].TeamID);
                            if (result.data[i].TeamID == "-2")
                                str += "<option value=\"-3\">" + result.data[i].TeamName + " (" + result.data[i].ObjCount + ")</option>";
                            else
                                str += "<option value=\"" + result.data[i].TeamID + "\">" + result.data[i].TeamName + " (" + result.data[i].ObjCount + ")</option>";
                        }
                    }
                }
                if (str == "") {
                    str = "<option value=\"-100\">暂无分组</option>";
                }
            }
            //alert(str);
            $(obj).parent().find("select.ddlTeams").html(str);
            return false;
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            alert(errorThrown);
        }
    });

   
}


function SubmitLoading() {
    $("#DivLoading").show();
}
function HiddenSubmitLoading() {
    $("#DivLoading").hide();
}
//---------------超级账号 end----------------------